<template>
  <div class="admin">
     <van-nav-bar
     class="head"
      :title="title"
      left-arrow
      border
      @click-left="onClickLeft"
    />
     <router-view @backPath="backPath" class="container" />
  </div>
</template>
<script>
export default {
  name: 'Admin',
  data () {
    return {
      title: '',
      path: ''
    }
  },
  created () {
    // 隐藏客户端头部
    if (navigator.userAgent.indexOf('iphone') > -1) {
      window.location.href = 'ios:hideH5Title00(0)'// 调用ios的函数
    } else {
      window.injs.hideH5Title00(0)// 通过injs接口调用android的函数
    }
  },
  watch: {
    $route: {
      handler (val, oldval) {
        // 头部标题
        this.title = val.meta.title
      },
      immediate: true
    }
  },

  methods: {
    /*  使用时 组件内 beforeRouteEnter传值和 beforeRouteLeave清空 */
    onClickLeft () {
      // 如果有值，按值导航跳转，没有则默认back
      if (this.path) {
        this.$router.push(this.path)
      } else {
        this.$router.back()
      }
    },
    backPath (val) {
      this.path = val
    }
  }

}
</script>
<style lang="less" scoped>
.head{
  width: 100%;
  position:relative;
  top: 0;
  left: 0;
}
.container{
  height: calc(100vh - 44px);
  overflow-y: auto;
}
</style>
